using System;
using System.Collections;
using UnityEngine;

public class IOSCamera : ISN_Singleton<IOSCamera>
{
	public const string IMAGE_PICKED = "image_picked";

	public const string IMAGE_SAVED = "image_saved";

	public Action<IOSImagePickResult> OnImagePicked = delegate
	{
	};

	public Action<ISN_Result> OnImageSaved = delegate
	{
	};

	private bool IsWaitngForResponce;

	private void Awake()
	{
		UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
	}

	public void SaveTextureToCameraRoll(Texture2D texture)
	{
	}

	public void SaveScreenshotToCameraRoll()
	{
		StartCoroutine(SaveScreenshot());
	}

	public void GetVideoPathFromAlbum()
	{
	}

	public void GetImageFromCamera()
	{
		if (!IsWaitngForResponce)
		{
			IsWaitngForResponce = true;
		}
	}

	public void GetImageFromAlbum()
	{
		if (!IsWaitngForResponce)
		{
			IsWaitngForResponce = true;
		}
	}

	private void OnImagePickedEvent(string data)
	{
		IsWaitngForResponce = false;
		IOSImagePickResult iOSImagePickResult = new IOSImagePickResult(data);
		dispatch("image_picked", iOSImagePickResult);
		if (OnImagePicked != null)
		{
			OnImagePicked(iOSImagePickResult);
		}
	}

	private void OnImageSaveFailed()
	{
		ISN_Result iSN_Result = new ISN_Result(false);
		dispatch("image_saved", iSN_Result);
		OnImageSaved(iSN_Result);
	}

	private void OnImageSaveSuccess()
	{
		ISN_Result iSN_Result = new ISN_Result(true);
		dispatch("image_saved", iSN_Result);
		OnImageSaved(iSN_Result);
	}

	private IEnumerator SaveScreenshot()
	{
		yield return new WaitForEndOfFrame();
		int width = Screen.width;
		int height = Screen.height;
		Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
		tex.ReadPixels(new Rect(0f, 0f, width, height), 0, 0);
		tex.Apply();
		SaveTextureToCameraRoll(tex);
		UnityEngine.Object.Destroy(tex);
	}
}
